import { useLocation } from "react-router-dom";
import { findMatchedRoute } from "@/utils/auth/auth";

const baseTitle = process.env.REACT_APP_TITLE;

export function usePageTitleGuard(routes) {
  const location = useLocation();
  //   获取对应路由下的meta属性，获取标签

  let route = findMatchedRoute(
    routes[routes.length - 1].children,
    location.pathname
  );

  let pageTitle = route?.meta?.title || route?.name;
  document.title = pageTitle ? `${pageTitle} | ${baseTitle}` : baseTitle;
}
